﻿using System.Collections.Generic;
using System.Reflection;

namespace ElectronicCommerce.Framework.Utility
{
    /// <summary>
    /// Property Extendsions
    /// </summary>
    public static class PropertyExtensions
    {
        /// <summary>
        /// 获取一个对象的所有公共属性名集合
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string[] PublicPropertyNames(this object obj)
        {
            List<string> propertyNameList = new List<string>();
            PropertyInfo[] properties = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo propertyInfo in properties)
            {
                propertyNameList.Add(propertyInfo.Name);
            }

            return propertyNameList.ToArray();
        }
    }
}
